package com.meyoung.driver;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
//浏览器封装
public class SeleniumDriver {
    public static WebDriver driver;
    public static WebDriver open(String browser){
        //寻找driver路径
        String path =System.getProperty("user.dir");
        if (browser.equals("chrome")){
            System.setProperty("webdriver.chrome.driver",path + "/drivers/chromedriver.exe");
            driver =new ChromeDriver();
        }else if(browser.equals("ie")){
            System.setProperty("webdriver.ie.driver",path + "/drivers/IEDriverServer.exe");
            driver = new InternetExplorerDriver();
        }else if(browser.equals("firefox")){
            //System.setProperty("webdriver.firefox.driver",path + "/drivers/geckodriver.exe");
            driver = new FirefoxDriver();
        }else {
            System.err.println("你传入的浏览器名称有误：" + browser);
        }
        return driver;
    }
    //关闭浏览器封装
    public static void closedAll(){
        driver.quit();

    }
    public static void closed(){
        driver.close();

    }
}
